﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Wicresoft.Web.Controls
{
    public partial class EditDropDownList : System.Web.UI.UserControl
    {
        /// <summary>
        /// AutoComplete获取数据的URL 
        /// </summary>
        public string AutoCompleteSource { get; set; }
        /// <summary>
        /// AutoComplete最小提示数
        /// </summary>
        public int MinLength { get; set; }
        /// <summary>
        /// 给出JQuery的引用地址
        /// </summary>
        public string Jquery { get; set; }
        /// <summary>
        /// 给出JqueryUI的引用地址以实现AutoCompete功能
        /// </summary>
        public string JqueryUi { get; set; }
        /// <summary>
        /// 给出JQueryUI的样式地址
        /// </summary>
        public string JqueryUiCss { get; set; }

        public DropDownList ThisControl
        {
            get {
                return this.dpl;
            }
        }

        public int SelectedIndex
        {
            get
            {
                return this.dpl.SelectedIndex;
            }
            set
            {
                this.dpl.SelectedIndex = value;
            }
        }

        public ListItem SelectedItem
        {
            get
            {
                return this.dpl.SelectedItem;
            }
        }

        public string SelectedValue
        {            
            get
            {
                if (!string.IsNullOrEmpty(Text)){
                    ListItem li = dpl.Items.FindByText(Text);
                    if (li != null)
                        return li.Value;
                    else
                        return "-1";
                }
                return this.dpl.SelectedValue;
            }
            set
            {
                this.dpl.SelectedValue = value;
            }
        }

        public string Text
        {
            get
            {
                return this.txt.Text;
            }
        }

        public override void DataBind()
        {
            dpl.DataBind();
        }

        public object DataSource
        {
            set { this.dpl.DataSource = value; }
        }
    }
}